package com.wva.video.consumer.videoprocess;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.wva.video.constant.ProcessConst;
import com.wva.video.domain.dto.VideoProcessDTO;
import com.wva.video.domain.po.Video;
import com.wva.video.enums.VideoStatus;
import com.wva.video.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: hong
 * @Date: 2025/2/17 15:33:39
 */
@Component
@RabbitListener(queues = "video.process.censor.machine")
@Slf4j
public class MachineCensorQueueConsumer {
    @Autowired
    VideoService videoService;

    @RabbitHandler
    void handle(VideoProcessDTO videoProcessDTO) throws InterruptedException, JsonProcessingException {
        Long videoId = videoProcessDTO.getVideoId();
        log.info("视频{}开始机器审核", videoId);

        //暂未实现机器审核

        //直接通过
        //标记等待人工审核
        if (ProcessConst.MANUAL_AUDIT_ENABLED) {
            videoService.updateById(
                    Video.builder()
                            .id(videoId)
                            .status(VideoStatus.WAIT_MANUAL_AUDIT.getStatus())
                            .build()
            );
        } else {
            videoService.updateById(
                    Video.builder()
                            .id(videoId)
                            .status(VideoStatus.NORMAL.getStatus())
                            .build()
            );
        }

        log.info("等待人工审核");
    }
}
